#include "UtilityPCH.h"
#include "UT_Timer.h"

using namespace Utility;
//----------------------------------------------------------------------------
//UT_Timer
//----------------------------------------------------------------------------
UT_Timer::UT_Timer()
{
	m_fCurrentTime  = 0.0;
	m_fTimeStep		= 0.0;	
	m_bTimerStart	= false;
}
//----------------------------------------------------------------------------
UT_Timer::~UT_Timer()
{
}
//----------------------------------------------------------------------------
void UT_Timer::StartTimer(float fCurrentTime,float fTimeStep,int16_t iLoopCount)
{
	m_fCurrentTime	= fCurrentTime;
	m_fTimeStep		= fTimeStep;
	m_iLoopCount	= iLoopCount;
	m_bTimerStart	= true;
}
//----------------------------------------------------------------------------
bool UT_Timer::IsTimerTrigger(float fCurrentTime)
{
	if(m_bTimerStart)
	{
		if( (fCurrentTime - m_fCurrentTime) > m_fTimeStep )
		{
			m_fCurrentTime = fCurrentTime;
			if(m_iLoopCount > 0)
				m_iLoopCount --;

			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
}
//----------------------------------------------------------------------------
bool UT_Timer::IsExpired(float fCurrentTime)
{
	if(m_bTimerStart)
	{
		if(m_iLoopCount == 0)
			return true;
		else
			return false;
	}
	else
	{
		return false;
	}
}
//----------------------------------------------------------------------------
void UT_Timer::StopTimer()
{
	m_fCurrentTime	= 0.0;
	m_fTimeStep		= 0.0;
	m_iLoopCount	= 0;
	m_bTimerStart	= false;
}